<?php
/**
  * DGF
  *
  *
  * @copyright Copyright (c) 2012 - 2014, huxiaomin
  * @author huxiaomin    2012-5-13  
  * @since		Version 1.0
  *
  */


class DThread{
       
	   private $threads = array();

       function __construct(){
       
       }
       
       
       public function getAsn($url,&$errno,&$errstr,$time_out = 5) {
        
        $arr = parse_url($url);
        $arr['port'] || $arr['port'] = 80;
        $fp = fsockopen($arr['host'],$arr['port'],$errno,$errstr,$time_out);
        if($fp) {
        	$arr['query'] && $arr['query'] = '?'.$arr['query'];
	        $out = "GET ".$arr['path'].$arr['query']." HTTP/1.1\r\n";
	        $out .= "Host: ".$arr['host']."\r\n";
	        $out .= "Connection: Close\r\n\r\n";
	        fwrite($fp,$out);
	        fclose($fp);
        }
        
      }
    
       
       public function postAsn($url,$post_arr,&$errno,&$errstr,$time_out = 5) {
	        $arr = parse_url($url);
	        $arr['port'] || $arr['port'] = 80; 
	        $fp = fsockopen($arr['host'],$arr['port'],$errno,$errstr,$time_out);
	        if($fp) {
	            $post_data = "";
	            if($post_arr){
	                foreach ($post_arr as $k=>$v) {
	                    $post_data .=rawurlencode($k).'='.rawurlencode($v).'&'; 
	                }
	                
	                $post_data = substr($post_data,0,-1);
	            }
	            $data_len = strlen($post_data);
	            
	            $arr['query'] && $arr['query'] = '?'.$arr['query'];
	            $out = "POST ".$arr['path'].$arr['query']." HTTP/1.1\r\n";
	            $out .= "Host: ".$arr['host']."\r\n";
	            $out .= "Content-type:application/x-www-form-urlencoded\r\n";  
	            $out .= "Connection: Close\r\n";
	            $out .= "Content-Length:$data_len\r\n\r\n"; 
	            $out .= $post_data."\r\n";
	            fwrite($fp,$out);
	            fclose($fp);
	        }
	        
       }
       

}